<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>{{ config('app.name') }}</title>
	<!-- 1.添加meta csrf_token -->
	<meta name="csrf-token" content="{{ csrf_token() }}">
	<!-- 1.引入 -->
    <link href="{{ asset('/bootstrap/css/bootstrap.min.css') }}" rel="stylesheet">
	<script src=" {{ asset('/js/jquery-1.8.3.min.js') }} "></script>
	<script>    
		<!-- 2.设置全局ajax选项 -->
		$.ajaxSetup({
			headers: {
				'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
			}
		});
		// 获取 token
		var _token = $('meta[name="csrf-token"]').attr('content');
		
		
		// 获取二级分类
		function getSecCategory( category_id )
		{
			// 是否加载
			var isLoad = $('#'+category_id).attr('isLoad');
			// 未加载
			if( isLoad=='false' )
			{
				// 获取相对应的子类列表 
				$.ajax({
					type:"post",
					url:"{{ url('/category/getSecCategory') }}",
					data:{category_id:category_id,_token:_token},
					async:false,    						
					dataType:"html",
					success:function(back){
						if( back!='' ){
							$('#'+category_id).after(back);
							// 设置为已加载
							$('#'+category_id).attr('isLoad','true');
						}
					}
				});
			}
		}
		

	</script>
</head>
<body>
<?php
	// 使用 分类 类
	use App\Http\Controllers\Admin\CategoryController;
	// 获取所有一级分类
	$all_first_category = CategoryController::getFirstAll();
?>
<!-- 导航栏  -->
<div data-example-id="navbar-fixed-to-top" class="bs-example bs-navbar-top-example" >
	<!-- 添加 .navbar-fixed-top 类可以让导航条固定在顶部 -->
	<nav class="navbar navbar-default navbar-fixed-top navbar-inverse" >
		<div class="container-fluid" >
			
			<div class="navbar-header"  >
				<a href="{{ url('/') }}" class="navbar-brand" style="font-size:21px;">Car Club</a>
			</div>

			<div id="bs-example-navbar-collapse-6" class="collapse navbar-collapse">
			  <ul class="nav navbar-nav text-center">
				<!-- 下拉选项 -->
				<!-- <li class="active"> -->
				<!-- <li class="dropdown"> -->
				
				<!-- 所有一级分类 -->
				@forelse($all_first_category as $all_category)
					<li>
						<a class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false" style="font-size:18px;" onmouseover='getSecCategory({{ $all_category->id }});' 
						id="{{ $all_category->id }}" isLoad='false' >
							{{ $all_category->name }} 
							<span class="caret"></span>
						</a>	
					</li>
				@empty
				@endforelse

				@if( session('user_name') )
					<li>
						<a href="{{ url('/orderList') }}/{{ session('user_id') }}" style="font-size:15px;" >
							{{ session('user_name') }}
						</a>
					</li>	
					<!-- 
						分割线
						<li role='separator' class='divider'></li> 
					-->
					<li>
						<a href="{{ url('/cart') }}" style="font-size:15px;" > 
							购物车
							<span class="badge">{{ session('cartTotal') }}</span>
						</a>
					</li>
					<li>
						<a href="{{ url('/loginOut') }}" style="font-size:15px;" > 
							退出
						</a>
					</li>
				@else
					<li>
						<a href="{{ url('/login') }}" style="font-size:15px;" >
							登录
						</a>
					</li>
					<li>
						<a href="{{ url('/cart') }}" style="font-size:15px;" > 
							购物车
							<span class="badge">{{ session('cartTotal') }}</span>
						</a>
					</li>
				@endif
				<li>
					<a href="{{ url('/comOrder') }}" style="font-size:15px;" >
						商品排行榜
					</a>
				</li>	
			  </ul>
			</div>
      </div>
    </nav>
</div>



